package com.gmzg.gmzgnews.news;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.gmzg.gmzgnews.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class WebViewActivity extends AppCompatActivity {

    @BindView(R.id.news_web_view_activity)
    WebView mNewsWebViewActivity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_view);
        ButterKnife.bind(this);
        String extra = getIntent().getStringExtra("998");
        String s = getIntent().getStringExtra("997");

        //可以解决图片不左右移动的问题
        String html= "<html><head><style>img {width:100%}</style></head><body>" + extra + "</body><ml>";
//        mNewsWebViewActivity.loadData(extra,"text/html", "utf-8");
        mNewsWebViewActivity.loadDataWithBaseURL(null, html, "text/html","UTF-8", null);
        WebSettings settings = mNewsWebViewActivity.getSettings();
        mNewsWebViewActivity.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        mNewsWebViewActivity.getSettings().setLoadWithOverviewMode(true);
        settings.setSupportZoom(false);
        mNewsWebViewActivity.getSettings().setJavaScriptEnabled(true);
        mNewsWebViewActivity.setWebViewClient(new WebViewClient(){
            public boolean shouldOverrideUrlLoading(WebView view,String url){
                view.loadUrl(url);
                return true;
            }
        });
        mNewsWebViewActivity.loadUrl(s);
    }
}
